﻿using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
namespace www.Controllers
{
    public class XMLClass
    {
        private const string _path = "~/SiteMap.xml";
        XDocument _doc;
        public void WriteUrl(string loc, string date, string changefreq, string priority)
        {
            _doc = XDocument.Load(HttpContext.Current.Request.MapPath(_path));
            var root = _doc.Element("urlset");
            if (root != null)
            {
                root.Add(new XElement("url",
                   new XElement("loc", new XText(loc)),
                   new XElement("lastmod", new XText(date)),
                   new XElement("changefreq", new XText(changefreq)),
                   new XElement("priority", new XText(priority))));

                _doc.Save(HttpContext.Current.Request.MapPath(_path));
            }
               
            
        }
        public IEnumerable<XElement> ReadUrl()
        {
            var exl = XElement.Load(HttpContext.Current.Request.MapPath(_path));

            var v = from page in exl.Elements("url")
                    select page;
            return v;
        }
    }
}